from appium.webdriver.common.appiumby import AppiumBy
from base.base_page import BasePage  # 需根据实际项目导入 BasePage 基类


class BatchShipmentPage(BasePage):
    # 页面标题
    PAGE_TITLE = (AppiumBy.XPATH, "//android.widget.TextView[@text='批量寄']")
    # 去绑定客户编码提示栏 - 去绑定按钮
    GO_BIND_BUTTON = (AppiumBy.XPATH, "//android.widget.TextView[@text='去绑定']")
    # 去绑定客户编码提示栏 - 关闭按钮
    CLOSE_TIP_BUTTON = (AppiumBy.XPATH, "//android.widget.TextView[@text='X']")  # 假设关闭按钮是 "X" 文本，实际按 App 调整
    # 寄件人信息区域 - 寄件人名称及电话（测试 13751056424 ）
    SENDER_INFO = (AppiumBy.XPATH, "//android.widget.TextView[contains(@text,'测试 13751056424')]")
    # 寄件人地址簿按钮
    SENDER_ADDRESS_BOOK = (AppiumBy.XPATH, "//android.widget.TextView[@text='地址簿' and @resource-id='...']")  # 补充准确 resource-id
    # 货好时间选择按钮
    GOODS_READY_TIME_BUTTON = (AppiumBy.XPATH, "//android.widget.TextView[@text='请选择' and @resource-id='...']")  # 补充准确 resource-id
    # 委托取货入口（请上传取货资料/图片 ）
    CONSIGN_PICKUP_ENTRY = (AppiumBy.XPATH, "//android.widget.TextView[@text='请上传取货资料/图片' and @resource-id='...']")  # 补充准确 resource-id
    # 给司机捎句话入口（给取货司机留言... ）
    MESSAGE_TO_DRIVER_ENTRY = (AppiumBy.XPATH, "//android.widget.TextView[@text='给取货司机留言，请在此填写' and @resource-id='...']")  # 补充准确 resource-id
    # 本次寄件信息统一开关
    SHIPMENT_INFO_UNIFIED_SWITCH = (AppiumBy.XPATH, "//android.widget.Switch[@resource-id='...']")  # 补充准确 resource-id
    # 新增收件人按钮（0/10 ）
    ADD_RECEIVER_BUTTON = (AppiumBy.XPATH, "//android.widget.TextView[@text='新增收件人(0/10)']")
    # 智能识别按钮
    SMART_RECOGNITION_BUTTON = (AppiumBy.XPATH, "//android.widget.TextView[@text='智能识别']")
    # 电子运单条约条款勾选框
    WAYBILL_TERMS_CHECKBOX = (AppiumBy.XPATH, "//android.widget.CheckBox[@resource-id='...']")  # 补充准确 resource-id
    # 电子运单条约条款文本（可点击查看详情）
    WAYBILL_TERMS_TEXT = (AppiumBy.XPATH, "//android.widget.TextView[@text='《电子运单契约条款》']")
    # 下单按钮
    PLACE_ORDER_BUTTON = (AppiumBy.XPATH, "//android.widget.TextView[@text='下单' and @resource-id='...']")  # 补充准确 resource-id

    # ---------------------- 操作方法 ----------------------
    def click_go_bind(self):
        """点击“去绑定”按钮，进入客户编码绑定流程"""
        self.click(self.GO_BIND_BUTTON)

    def click_close_tip(self):
        """点击关闭提示栏按钮，隐藏“下单需绑定客户编码”提示"""
        self.click(self.CLOSE_TIP_BUTTON)

    def click_sender_address_book(self):
        """点击寄件人地址簿，选择/修改寄件人地址"""
        self.click(self.SENDER_ADDRESS_BOOK)

    def click_goods_ready_time(self):
        """点击货好时间选择按钮，展开时间选择器"""
        self.click(self.GOODS_READY_TIME_BUTTON)

    def click_consign_pickup(self):
        """点击委托取货入口，上传取货资料/图片"""
        self.click(self.CONSIGN_PICKUP_ENTRY)

    def click_message_to_driver(self):
        """点击给司机捎句话入口，填写留言内容"""
        self.click(self.MESSAGE_TO_DRIVER_ENTRY)

    def toggle_shipment_info_unified(self):
        """切换“本次寄件信息统一”开关状态（开启/关闭）"""
        self.click(self.SHIPMENT_INFO_UNIFIED_SWITCH)

    def click_add_receiver(self):
        """点击新增收件人按钮，添加收件人信息"""
        self.click(self.ADD_RECEIVER_BUTTON)

    def click_smart_recognition(self):
        """点击智能识别按钮，通过识别功能添加收件人等信息"""
        self.click(self.SMART_RECOGNITION_BUTTON)

    def check_waybill_terms(self):
        """勾选电子运单条约条款"""
        self.click(self.WAYBILL_TERMS_CHECKBOX)

    def click_place_order(self):
        """点击下单按钮，提交批量寄件订单"""
        self.click(self.PLACE_ORDER_BUTTON)